package com.etc.demo.controller.user;

import com.etc.common.BaseController;
import com.etc.demo.po.Member;
import com.etc.demo.service.user.IUserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.HashMap;
import java.util.List;

@RequestMapping("demo")
@Controller
public class UserDemoController extends BaseController {

    private static final Logger logger = LoggerFactory.getLogger(UserController.class);
    @Autowired
    IUserService service;

    /**
     * ユーザ画面初期化勝利
     * @param model
     * @return
     */
    @GetMapping("user")
    public String inituser(Model model) {

        if (application.getAttribute("dlist") == null) {
            List<HashMap> dlist = service.findAllDeptInfo();
            this.application.setAttribute("dlist", dlist);
        }

        return "demo/user";
    }
    /**
     * ユーザ画面検索ボタンをクリック後、検索処理
     * @param params
     * @param model
     * @return
     */
    @GetMapping("usersearch")
    public String usersearch(@RequestParam HashMap params, @RequestParam(defaultValue="1",required=true,value="pageNo") Integer pageNo, Model model) {

        Integer pageSize=10;//每页显示记录数
        //分页查询
        PageHelper.startPage(pageNo, pageSize);
        List<Member> mlist = service.findMemberByCondtion(params);
        PageInfo<Member> pageInfo=new PageInfo(mlist);

        model.addAttribute("mlist", pageInfo);
        return "demo/user";
    }
}
